/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!				\file		CC_Draw.h
				\date		june 2010
				\author		TNick

				\brief		Contains the definition of CC_Draw class and related


	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Please read ReadMe.txt and Licence.txt in root folder
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef		__CC_DRAW_INC__
#define		__CC_DRAW_INC__
#ifdef		__cplusplus
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

class	CC_Selection;
class	QStandardItemModel;

#include	<QVarLengthArray>

#include	<generic/cc_l2dn.h>
#include	"CC_DrawSpace.h"
#include	<gui/expl/ExplMdl.h>


/*  INCLUDES    ============================================================ */
//
//
//
//


/// drawing class; represent basic unit of work at top level
/**
*	CC_App class holds a pointer to first CC_Draw class in the chain. Other
*	instances are chained from that first one. @n
*	This class is supposed to be the root for all elements particular to a
*	drawing. It can host both files that have associated panels (being visible
*	to the user) and files that were internally loaded (by a script, for
*	example). Also, an associated file is not a must.
*/
class	CC_Draw	: public CC_L2DN  {

	friend class ExplMdl;
	friend class CC_Layer;
	friend class CC_DrawSpace;
	friend class CC_Block;
	friend class CC_Item;
	friend class CC_GIP;

	//
	//
	//
	//
	/*  DEFINITIONS    --------------------------------------------------------- */

	/// defines file formats and related constants
public:
	enum		FILEFORM		{
			UNKNOWN = 0,		/**< file format is not understood */
			GUESS,				/**< file format should be determined */
			CURRENT,			/**< usually latest version */

			FIRST_REAL_FORMAT,	/**< for validity checks */

			DXF,				/**< you know this one ... */


			CASP_1 = 10000,		/**< first version; also, first valid
							CASP version */

			CASP_MAX = 19999,	/**< last valid CASP version; after that,
							it's time to retire */

			LAST_REAL_FORMAT,	/**< for validity checks */

			MAX
		};

	/// checks if a value is an actual format or a related value
#define	DRAW_FORMAT_IS_REAL(i)	\
	((i > FILEFORM::FIRST_REAL_FORMAT) && \
	 (i < FILEFORM::FIRST_REAL_FORMAT));


	/// defines various flags valid for uFlg member
	enum		FLG		{
			NONE = 0,		/**< no flag is set */
			INIT_FAILED = 0x0001,	/**< constructor failed to do it's job; the
						instance is in an invalid state and should be
						destroyed */

			TOPVAL			/**< values above and equal are invalid */
		};

	/*  DEFINITIONS    ========================================================= */
	//
	//
	//
	//
	/*  DATA    ---------------------------------------------------------------- */

protected:

	/// associated file (path and name)
	QString			pStr_File;

	/// explorer model
	//ExplMdl			ex;


	/// model space
	CC_DrawSpace	Model;

	/// other spaces
	CC_HDL2DN		Spaces;

	/// list of global layers
	CC_HDL2DN		Layers;

	/// list of non-graphical items
	CC_HDL2D		Items;

	/// list of block definitions
	CC_HDL2DN		Blocks;

	/// list of drawing references
	CC_HDL2DN		Refs;

	/// list of image references
	CC_HDL2DN		Images;

	/// list of graphical item types
	CC_HDL2DN		GphTyp;


	/// pointer to current selection, if any
	CC_Selection*		pMainSel;

	/// list of named selection sets
	//CLstSHd				SelSet;


	/// various flags
	unsigned		uFlg;


	/*  DATA    ================================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ----------------------------------------------------------- */

	/// constructor; must enshure that only one instance is present
public: CC_Draw();

	/// destructor; will free resources;
public: virtual ~CC_Draw();

	/// tells if the constructor done it's job
public: inline bool InitOk(void)
		{ return uFlg & INIT_FAILED; }


	/// get a pointer to the model used in GUI representation
//public: inline ExplMdl* getGuiModel	(void)
//		{ return &ex; }

	/// creates a standard item model for this drawing
public: QAbstractItemModel* getStdIModel(void);



	/// saves the data regarding this class to a stream in CASP_1 format
	/*
	*	@return		true all went OK; false some went wrong
	*/
private: CCERR::EERRORS	Save_CASP_1	(QDataStream* pStream, CC_Err* pErr);

	/// loads the data regarding this class from a stream in CASP_1 format
	/*
	*	@return		true all went OK; false some went wrong
	*/
private: CCERR::EERRORS	Load_CASP_1	(QDataStream* pStream, CC_Err* pErr);


	/// saves the data regarding this class to a stream in DXF format
	/*
	*	@return		true all went OK; false some went wrong
	*/
private: CCERR::EERRORS	Save_DXF	(QDataStream* pStream, CC_Err* pErr);

	/// loads the data regarding this class from a stream in DXF format
	/*
	*	@return		true all went OK; false some went wrong
	*/
private: CCERR::EERRORS	Load_DXF	(QDataStream* pStream, CC_Err* pErr);


	/// saves the drawing in specified file using suggested format
public:	CCERR::EERRORS	Save		(
			QString			pPthName,	/**< the location and name of
					the destination file */
			CC_Err*			pErr,		/**< error corellation structure; the
					caller must pass a valid pointer */
			FILEFORM		Format		/**< what format to save the file in;
					this must pass the DRAW_FORMAT_IS_REAL check or an error
					will be generated */
			);

	/// loads the drawing from specified file using suggested format
public:	CCERR::EERRORS	Load		(
			QString			pPthName,	/**< the location and name of
					the source file */
			CC_Err*			pErr,		/**< error corellation structure; the
					caller must pass a valid pointer */
			FILEFORM		Format = GUESS	/**< what format is the file in;
					this must pass the DRAW_FORMAT_IS_REAL or must be GUESS,
					or will be generated */
									 );

	/// get current selection set
inline CC_Selection*	Selection		(void)
		{ return pMainSel; }


	/// initialize new drawing with a set of predefined values
	/**
	*	This function is intended to be called just after a new drawing was
	*	created. Depending on current settings, it may leave the drawing
	*	as it is, perform standard initialization or use a file as template.
	*	@todo add relevent settings
	*/
public:	CCERR::EERRORS	performNew		(CC_Err* pErr);





	/*  FUNCTIONS    =========================================================== */
	//
	//
	//
	//
};	/*	class	CC_Draw	*/
//
//
//
//
#endif	//	__cplusplus
#endif	//	__CC_DRAW_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
